package danran.dp;

/**
 * @Classname OneAndZero
 * @Description TODO
 * @Date 2021/9/1 11:36
 * @Created by ASUS
 */
public class OneAndZero {

    public int findMaxForm(String[] strs, int m, int n) {
        int[][] dp = new int[m + 1][n + 1];
        for (String str : strs) {
            // 得到每个字符串中1和0的个数
            int zero = 0, one = 0;
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) == '1') one++;
                else zero++;
            }
            for (int i = m; i >= zero; i--) {
                for (int j = n; j >= one ; j--) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - zero][j - one] + 1);
                }
            }
        }
        return dp[m][n];
    }
}
